<!-- 选择生日 -->
<template>
  <div>
    <van-datetime-picker
      v-model="currentdate"
      type="date"
      title="选择年月日"
      :min-date="minDate"
      :max-date="maxDate"
      @confirm="onConfirm"
      @cancel="$emit('close')"
    />
  </div>
</template>

<script>
import { updateUserProfile } from "../../../api/user.js";
import dayjs from "dayjs";
import { Toast } from "vant";
export default {
  name: "SelectBirthday",

  data() {
    return {
      currentdate: new Date(),
      minDate: new Date(1999, 0, 1),
      maxDate: new Date(),
    };
  },
  methods: {
    async onConfirm(value) {
      try {
        Toast.loading({
          forbidClick: true,
          message: "保存中..",
        });
        const date = dayjs(value).format("YYYY-MM-DD");
        const data = await updateUserProfile({
          birthday: date,
        });
        console.log(data);
        Toast.success("更新成功");
        this.$emit("input", date);
        this.$emit("close");
      } catch (err) {
        Toast.fail("更新失败");
        console.log(err);
      }
    },
  },
};
</script>

<style lang="less" scoped>
</style>